﻿using HandyControl.Themes;
using HandyControl.Tools;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using HandyControl.Controls;
using HandyControl.Properties.Langs;
using qubaohe.ViewModels;
using System.Diagnostics;
using System.Linq;
using System.Collections.ObjectModel;
namespace qubaohe.Views
{
    public partial class MainWindow:BlurWindow
    {
        public MainWindow()
        {
            
            ConfigHelper.Instance.SetLang("zh-cn");//设置语言 
            InitializeComponent();
            
        }

        #region Change Theme
        private void ButtonConfig_OnClick(object sender, RoutedEventArgs e) => PopupConfig.IsOpen = true;

        private void ButtonSkins_OnClick(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is Button button)
            {
                PopupConfig.IsOpen = false;
                if (button.Tag is ApplicationTheme tag)
                {
                    ((App)Application.Current).UpdateTheme(tag);
                }
                else if (button.Tag is Brush accentTag)
                {
                    ((App)Application.Current).UpdateAccent(accentTag);
                }
                else if (button.Tag is "Picker")
                {
                    var picker = SingleOpenHelper.CreateControl<ColorPicker>();
                    var window = new PopupWindow
                    {
                        PopupElement = picker,
                        WindowStartupLocation = WindowStartupLocation.CenterScreen,
                        AllowsTransparency = true,
                        WindowStyle = WindowStyle.None,
                        MinWidth = 0,
                        MinHeight = 0,
                        Title = "Select Accent Color"
                    };

                    picker.SelectedColorChanged += delegate
                    {
                        ((App)Application.Current).UpdateAccent(picker.SelectedBrush);
                        window.Close();
                    };
                    picker.Canceled += delegate { window.Close(); };
                    window.Show();
                }
            }
        }


        #endregion

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var dataGrid1 = sender as DataGrid;
            var items = dataGrid1.SelectedItems.Cast<SongItem>().ToList();
            var observableCollection = new ObservableCollection<SongItem>(items);
            var mainWindowViewModel = (MainWindowViewModel)DataContext;
            mainWindowViewModel.SelectedItems = observableCollection;

            //foreach (var item in items)
            //{
            //    var songItem = item as SongItem;
            //    if (songItem != null)
            //    {
            //        str += songItem.SongName + "\n";
            //    }
            //}
            ////HandyControl.Controls.MessageBox.Show(str);
            //Debug.WriteLine(str);


        }
    }
}
